home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Very Best of Atari Inside
/
The Very Best of Atari Inside 1.iso
/
mint
/
mntlib43
/
mntlib
/
div.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-15
|
1KB
|
77 lines
/*
* div and ldiv
* this one should be compat with -fpcc-struct-return
*
* ++jrb bammi@dsrgsun.ces.cwru.edu
*/
#include <stdlib.h>
#ifdef __GNUC__
long __divsi3(long, long); /* returns: quot in d0.l remainder in d1.l */
#ifdef __MSHORT__
div_t div(int num, int denom)
{
div_t result;
__asm__ volatile("\
divs %4,%3 | %3/%2 must be a data reggie
movw %2,%0 | %2<31:16> == rem %2<15:0> == quot
swap %2
movw %2,%1"
: "=g"(result.quot), "=g"(result.rem), "=d"((long)num)
: "2"((long)num), "d"(denom)
);
return result;
}
#else /* !__MSHORT__ */
__asm__(".stabs \"_div\",5,0,0,_ldiv");
#endif
ldiv_t ldiv(long num, long denom)
{
ldiv_t result;
__asm__ volatile("\
movl %3,sp@-
movl %2,sp@-
jsr ___divsi3
addqw #8,sp
movl d0,%0
movl d1,%1"
: "=g"(result.quot), "=g"(result.rem)
: "r"(num), "r"(denom)
); /* compiler dependency, dont tell gcc about d0,d1 clobb */
return result;
}
#else /* !__GNUC__ */
div_t
div(num, denom)
int num, denom;
{
div_t res;
res.quot = num / denom;
res.rem = num % denom;
return res;
}
ldiv_t
ldiv(num, denom)
long num, denom;
{
ldiv_t res;
res.quot = num / denom;
res.rem = num % denom;
return res;
}
#endif /* !__GNUC__ */